﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using NHibernate.Criterion;

namespace Cms.Web.CmsSystem
{
    public partial class InnerIndex : System.Web.UI.Page
    {
        public string TreeJson;
        BLL.TabPage bll = new Cms.BLL.TabPage();
        protected void Page_Load(object sender, EventArgs e)
        {
            
            string tabid = EntLib.Request.GetString("tabid");
            if (!String.IsNullOrEmpty(tabid))
            {                
                List<Model.Sys_Tabpage> list = bll.GetAll();
                TreeJson = BuildTreeJson(list,tabid).Trim(System.Environment.NewLine.ToCharArray()).Trim(',');
            }
        }

        public string BuildTreeJson(List<Model.Sys_Tabpage> list,string tabid)
        {
            List<Model.Sys_Tabpage> listChild = bll.GetChilds(list, tabid);
            if (listChild.Count > 0)
            {
                StringBuilder sb = new StringBuilder();
                foreach (Model.Sys_Tabpage model in listChild)
                {
                    sb.Append("{");
                    sb.AppendFormat(" id: '{0}', pId: '{1}', name: '{2}',tabtype:'{3}'", model.Id, model.Parentid, model.Title,model.Tab_Type);
                    sb.AppendLine("},");
                    sb.Append(BuildTreeJson(list, model.Id));
                }
                return sb.ToString();
            }
            return "";
        }
    }
}
